home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / system / sysprof3.zip / TRANSFER.C < prev    next >
C/C++ Source or Header  |  1989-01-20  |  4KB  |  173 lines

  1. #include "stdio.h"
  2. #include "conio.h"
  3. #include "dos.h"
  4. #include "process.h"
  5. #include "malloc.h"
  6. #include "io.h"
  7.  
  8. void main(int,char *[]);
  9. void print_byte(char);
  10. void draw_point(int,int,int);
  11. void set_mode(int);
  12.  
  13. void main ( argc , argv )
  14.  
  15. int argc;
  16. char *argv[];
  17. {
  18. FILE *handle;
  19. long filesize;
  20. char *buffer , *ptr;
  21. unsigned idx , line_num , pixel;
  22. unsigned char first_byte , second_byte;
  23. unsigned char mask , color , first_bit , second_bit;
  24.  
  25.        /*  MAKE SURE A FILE NAME WAS SPECIFIED ON THE COMMAND LINE.  */
  26.  
  27. if (argc < 2)
  28.     {
  29.     printf("\nMust specify name of file to be printed.");
  30.     exit(1);
  31.     }
  32.  
  33.                             /*  OPEN THE FILE.  */
  34.  
  35. if ((handle = fopen(argv[1],"rb")) == NULL)
  36.     {
  37.     printf("\nCannot open %s.",argv[1]);
  38.     exit(1);
  39.     }
  40.  
  41.       /*  DETERMINE THE FILE SIZE, AND ALLOCATE A BUFFER TO HOLD IT.  */
  42.  
  43. filesize = filelength(fileno(handle));
  44. if ((filesize > 65535L) || ((buffer = malloc((unsigned)filesize)) == NULL))
  45.     {
  46.     printf("\nInsufficient memory.");
  47.     fclose(handle);
  48.     exit(1);
  49.     }
  50.  
  51.                     /*  READ THE FILE INTO THE BUFFER.  */
  52.  
  53. if (fread(buffer,sizeof(char),(unsigned)filesize,handle) != (unsigned)filesize)
  54.     {
  55.     printf("\nError reading %s.",argv[1]);
  56.     fclose(handle);
  57.     exit(1);
  58.     }
  59.  
  60.                             /*  CLOSE THE FILE.  */
  61.  
  62. fclose(handle);
  63.  
  64.                  /*  PRINT THE FIRST THREE BYTES OF THE FILE, 
  65.                 WHICH SET THE LINE SPACING ON THE PRINTER.  */
  66.  
  67. for (idx = 0 , ptr = buffer; idx < 3; idx++ , ptr++)
  68.     print_byte(*ptr);
  69.  
  70.                           /*  SET THE VIDEO MODE.  */
  71.  
  72. set_mode(4);
  73.  
  74.   /*  THE IMAGE IS DIVIDED INTO 25 LINES, EACH OF WHICH IS EIGHT PIXELS HIGH.  
  75.                 GO THROUGH ALL 25, PRINTING AND DISPLAYING.  */
  76.  
  77. for (line_num = 0; line_num < 25; line_num++)
  78.     {
  79.  
  80.        /*  THE FIRST THING ON EACH LINE IS A FOUR-BYTE CONTROL SEQUENCE, 
  81.           WHICH SETS UP THE PROPER GRAPHICS MODE ON THE PRINTER.  */
  82.  
  83.     for (idx = 0; idx < 4; idx++ , ptr++)
  84.         print_byte(*ptr);
  85.  
  86.       /*  THE NEXT 640 BYTES OF THE LINE CONSISTS OF 320 PAIRS OF BYTES.  
  87.           BY LOOKING AT A PARTICULAR BIT FROM THE FIRST BYTE, AND THE 
  88.            CORRESPONDING BIT FROM THE SECOND BYTE, YOU CAN TELL WHAT 
  89.                  COLOR THE PIXEL ON THE SCREEN SHOULD BE.  */
  90.  
  91.     for (idx = 0; idx < 320; idx++ , ptr += 2)
  92.         {
  93.         print_byte(first_byte = *ptr);
  94.         print_byte(second_byte = *(ptr+1));
  95.  
  96.         for (pixel = 0 , mask = 0x80; pixel < 8; pixel++ , mask >>= 1)
  97.             {
  98.             first_bit = (first_byte & mask) >> (7-pixel);
  99.             second_bit = (second_byte & mask) >> (7-pixel);
  100.             color = (first_bit << 1) | second_bit;
  101.             draw_point(idx,line_num*8+pixel,color);
  102.             }
  103.         }  /*  END OF FOR (IDX)  */
  104.  
  105.     /*  THE LAST THING ON EACH LINE IS A CARRIAGE RETURN AND LINE FEED.  */
  106.  
  107.     for (idx = 0; idx < 2; idx++ , ptr++)
  108.         print_byte(*ptr);
  109.     }  /*  END OF FOR (LINE_NUM)  */
  110.  
  111.                 /*  NOW PRINT THE LAST THREE BYTES OF THE FILE, 
  112.                WHICH RESET THE LINE SPACING ON THE PRINTER.  */
  113.  
  114. for (idx = 0; idx < 3; idx++ , ptr++)
  115.     print_byte(*ptr);
  116.  
  117.                            /*  FREE THE BUFFER.  */
  118.  
  119. free(buffer);
  120.  
  121.                  /*  WAIT FOR A KEYSTROKE, AND THEN EXIT.  */
  122.  
  123. getch();
  124. exit(0);
  125. }  /*  END OF MAIN  */
  126.  
  127. void print_byte ( ch )
  128.  
  129. char ch;
  130. {
  131. union REGS regs;
  132.  
  133. regs.x.dx = 0;
  134. regs.h.ah = 0;
  135. regs.h.al = ch;
  136. int86(0x17,®s,®s);
  137.  
  138. return;
  139. }  /*  END OF PRINT_BYTE  */
  140.  
  141.  
  142. void draw_point( col , row , color)
  143.  
  144. int col;
  145. int row;
  146. int color;
  147. {
  148. union REGS registers;
  149.  
  150. registers.x.dx = row;
  151. registers.x.cx = col;
  152. registers.h.al = (unsigned char)color;
  153. registers.h.ah = 0x0C;
  154.  
  155. int86(0x10,®isters,®isters);
  156. return;
  157. }
  158.  
  159. void set_mode ( mode )
  160.  
  161. int mode;
  162. {
  163. union REGS registers;
  164.  
  165. registers.h.ah = 0;
  166. registers.h.al = (unsigned char)mode;
  167.  
  168. int86(0x10,®isters,®isters);
  169. return;
  170. }
  171.  
  172.  
  173.